<?php

if(!defined('ADMIN')){
	exit('Access Denied');
}

if(isset($_GET["id"])){ $_POST['ids']=$_GET["id"];}

$id_arr=$_POST['ids'];

if(!empty($id_arr)){
    if(!is_array($id_arr)){
        $id_arr1[]=$id_arr;
    }else{
        $id_arr1=$id_arr;
    }
    //
    
    $row=$ezhand->select_all("modelfield",'id,modelid,field,formtype',"id in (".implode(",",$id_arr1).") and issys=0 ");
    if(!empty($row)){
        $modelid=$row[0]["modelid"];
        $formtype=$row[0]["formtype"];
        $tablename=$ezhand->select("model",'tablename','id="'.$modelid.'"');
        $tablename=$ezhand->TABLEPRE.$tablename;
        foreach($row as $r){
            $field=$r["field"];
            if($formtype=="province"){
            $sql="ALTER TABLE `".$tablename."` DROP `".$field."_province`;";
            $query=$ezhand->query($sql);    
            $sql="ALTER TABLE `".$tablename."` DROP `".$field."_city`;";
            $query=$ezhand->query($sql);    
            $sql="ALTER TABLE `".$tablename."` DROP `".$field."_district`;";
            $query=$ezhand->query($sql);                                            
            }
            $sql="ALTER TABLE `".$tablename."` DROP `".$field."`;";
            $query=$ezhand->query($sql);    
        }
    
    }
    
    $re=$ezhand->delete_id_in(implode(",",$id_arr1),"modelfield",0,' and issys=0');

}
if($re==1){
    jumpajax('200','删除完成','');
}
else{
    jumpajax('300','删除错误','');
}
?>